package com.heima.admin.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.admin.mapper.ChannelMapper;
import com.heima.admin.service.IChannelService;
import com.heima.api.IWemediaClient;
import com.heima.common.constants.CacheConstant;
import com.heima.model.admin.dtos.ChannelDto;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.pojos.WmChannel;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
@Slf4j
public class ChannelServiceImpl extends ServiceImpl<ChannelMapper, WmChannel> implements IChannelService {

    private final IWemediaClient channelClient;

    /**
     * 分页查询
     *
     * @param
     * @return
     */
    @Override
    @Cacheable(cacheNames = CacheConstant.CHANNEL ,key = "#dto.hashCode()")
    public ResponseResult getChannelPage(ChannelDto dto) {
      return channelClient.getChannelPage(dto);

    }

    /**
     * 根据id删除频道
     *
     * @param id
     * @return
     */
    @CacheEvict(cacheNames =  CacheConstant.CHANNEL,allEntries = true)
    @Override
    public ResponseResult channelDelete(Integer id) {
        return channelClient.deleteChannel(id);
    }

    /**
     * 新增频道
     *
     * @param wmChannel
     * @return
     */
    @Override
    @CacheEvict(cacheNames =  CacheConstant.CHANNEL,allEntries = true)
    public ResponseResult channelSave(WmChannel wmChannel) {
        return channelClient.channelSave(wmChannel);
    }

    /**
     * 更新频道
     *
     * @param wmChannel
     * @return
     */
    @Override
    @CacheEvict(cacheNames =  CacheConstant.CHANNEL,allEntries = true)
    public ResponseResult channelUpdate(WmChannel wmChannel) {
        return channelClient.channelUpdate(wmChannel);
    }
}
